/**
 * Created by L on 2017/6/2.
 */

var url="http://47.93.233.182/";


window.onload=function () {
//公司
    $.ajax({
        url:url+"/getCompanyInfo",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
             //动画
            donghua(text);
            //动态生成轮播图
            lunbo(text);
            //公司数据
            company(text);


        },
        error:function () {

        }
    });

//轨迹
    $.ajax({
        url:url+"/getTrajectory",
        type:'GET',
        dataType:'JSON',
        success:function (text) {

            guiji(text);
        },
        error:function () {

        }
    });

//荣誉
    $.ajax({
        url:url+"/getHonor",
        type:'GET',
        dataType:'JSON',
        success:function (text) {

            getHonor(text);
        },
        error:function () {

        }
    });



};

//荣誉
function getHonor(text) {
    var gloey1=document.getElementsByClassName("gloey-1")[0];
    var gloey2=document.getElementsByClassName("gloey-2")[0];
    var gloey3=document.getElementsByClassName("gloey-3")[0];

    var len=text.data.length;
    var arrNew=[];
    var arrMid=[];
    var arrOld=[];
    var a=0;
    var b=0;
    var c=0;
    for(var i=0;i<len;i++){
        if(text.data[i].time>2012){
            arrNew[a]=text.data[i];
            a++;
        }else if(text.data[i].time<=2012&&text.data[i].time>2007){
            arrMid[b]=text.data[i];
            b++;
        }else if(text.data[i].time<=2007){
            arrOld[c]=text.data[i];
            c++;
        }
    }


    for(var i=0;i<arrNew.length;i++){
        var honor=document.createElement("span");
        var p=document.createElement("p");
        gloey1.appendChild(honor);
        $(".gloey-1 span").eq(i).html(arrNew[i].time);

        gloey1.appendChild(p);
        $(".gloey-1 p").eq(i).html(arrNew[i].aboutcompany_content);

    }
    for(var i=0;i<arrMid.length;i++){
        var honor2=document.createElement("span");
        var p1=document.createElement("p");
        gloey2.appendChild(honor2);
        $(".gloey-2 span").eq(i).html(arrMid[i].time);

        gloey2.appendChild(p1);
        $(".gloey-2 p").eq(i).html(arrMid[i].aboutcompany_content);


    }
    for(var i=0;i<arrOld.length;i++){
        var honor3=document.createElement("span");
        var p2=document.createElement("p");
        gloey3.appendChild(honor3);
        $(".gloey-3 span").eq(i).html(arrOld[i].time);

        gloey3.appendChild(p2);
        $(".gloey-3 p").eq(i).html(arrOld[i].aboutcompany_content);

    }


}


//轨迹
function guiji(text) {
    var path1=document.getElementsByClassName("path-1")[0];
    var path2=document.getElementsByClassName("path-2")[0];
    var len=text.data.length;
    var arrNew=[];
    var arrOld=[];
    var b=0;
    var c=0;
    for(var i=0;i<len;i++){
        if(text.data[i].time>2008){
            arrNew[b]=text.data[i];
            b++;
        }else{
            arrOld[c]=text.data[i];
            c++;
        }
    }

    for(var i=0;i<arrNew.length;i++){
        var span=document.createElement("span");
        path1.appendChild(span);
        $(".path-1 span").eq(i).html("·"+arrNew[i].time+"·");

        var p=document.createElement("p");
        path1.appendChild(p);
        $(".path-1 p").eq(i).html(arrNew[i].aboutcompany_content);
    }

    for(var i=0;i<arrOld.length;i++){
        var span=document.createElement("span");
        path2.appendChild(span);
        $(".path-2 span").eq(i).html("·"+arrOld[i].time+"·");

        var p=document.createElement("p");
        path2.appendChild(p);
        $(".path-2 p").eq(i).html(arrOld[i].aboutcompany_content);
    }

}

//公司
function company(text) {
    var html=document.getElementsByClassName("cooperat")[0];
    html.innerHTML=text.data[0].aboutcompany_content;

    //写个正则
    var images=$(".cooperat img");
    for(var i=0;i<images.length;i++){
        var src=images.eq(i).attr("src");
        images.eq(i).attr("src",url+src);
    }
}


//轮播图动态生成
function lunbo(text) {
    var image=text.data[0].aboutcompany_image.split("+");
    var len=image.length-1;
    var box=document.getElementsByClassName("carousel-inner")[0];
    var box111=document.getElementsByClassName("carousel-indicators")[0];
    for(var i=0;i<len;i++){
        var item=document.createElement("div");
        item.setAttribute("class","item");
        box.appendChild(item);

        var box2=document.getElementsByClassName("item")[i];
        var picture=document.createElement("div");
        picture.setAttribute("class","picture");
        box2.appendChild(picture);
        $(".picture").eq(i).css("background","url("+url+image[i]+")no-repeat");
        $(".picture").eq(i).css("background-size","cover");

        var carouselCaption=document.createElement("div");
        carouselCaption.setAttribute("class","carousel-caption");
        box2.appendChild(carouselCaption);
        document.getElementsByClassName("carousel-caption")[i].innerText=i;

        var li=document.createElement("li");
        li.setAttribute("data-target","#carousel-example-generic");
        li.setAttribute("data-slide-to",i);
        box111.appendChild(li);
    }
    $(".carousel-indicators li").eq(0).attr("class","active");
    $(".item").eq(0).attr("class","item active");
}


//动画
function donghua(text) {



    var bg=$(".containt-us");

    var coop=$(".coop-btn");
    var pat=$(".path-btn");
    var glo=$(".gloey-btn");

    var coop2=$(".cooperat");
    var pat2=$(".path");
    var glo2=$(".gloey");

    var yearcontr97=$(".year-contr97");
    var yearcontr28=$(".year-contr28");

    var path1=$(".path-1");
    var path2=$(".path-2");

    var gloey1=$(".gloey-1");
    var gloey2=$(".gloey-2");
    var gloey3=$(".gloey-3");

    var yearcontr36=$(".year-contr36");
    var yearcontr82=$(".year-contr82");
    var yearcontr37=$(".year-contr37");

    var movie1=$("#movies");
    var shortfilm=$("#short-film");
    var tvplay=$("#tv-play");

    var movies1=$(".movies-1");
    var movies2=$(".movies-2");
    var movies3=$(".movies-3");

    movie1.on("click",function () {
        movies1.show(500);
        movies2.hide(500);
        movies3.hide(500);
    });

    shortfilm.on("click",function () {
        movies1.hide(500);
        movies2.show(500);
        movies3.hide(500);
    });

    tvplay.on("click",function () {
        movies1.hide(500);
        movies2.hide(500);
        movies3.show(500);
    });

    yearcontr36.on("click",function () {
        gloey1.show(500);
        gloey2.hide(500);
        gloey3.hide(500);
    });

    yearcontr82.on("click",function () {
        gloey1.hide(500);
        gloey2.show(500);
        gloey3.hide(500);
    });

    yearcontr37.on("click",function () {
        gloey1.hide(500);
        gloey2.hide(500);
        gloey3.show(500);
    });

    coop.on("click",function () {
        coop2.show(500);
        pat2.hide(500);
        glo2.hide(500);
        coop.css({"background-color":"#7fbfed"});
        pat.css({"background-color":"#fcca57"});
        glo.css({"background-color":"#fcca57"});
        bg.css("background","url(img/companey-bg.jpg)no-repeat center");
        bg.css("background-size","cover");
    });

    pat.on("click",function () {
        coop2.hide(500);
        pat2.show(500);
        glo2.hide(500);
        coop.css({"background-color":"#fcca57"});
        pat.css({"background-color":"#7fbfed"});
        glo.css({"background-color":"#fcca57"});
        bg.css("background","url(img/guiji.jpg)no-repeat center");
        bg.css("background-size","cover");
    });

    glo.on("click",function () {
        coop2.hide(500);
        pat2.hide(500);
        glo2.show(500);
        coop.css({"background-color":"#fcca57"});
        pat.css({"background-color":"#fcca57"});
        glo.css({"background-color":"#7fbfed"});
        bg.css({"background":"url(img/rongyu-bg.jpg)no-repeat center"});
        bg.css("background-size","cover");
    });

    yearcontr97.on("click",function () {
        path1.show(500);
        path2.hide(500);
    });
    yearcontr28.on("click",function () {
        path1.hide(500);
        path2.show(500);
    });

    $('.carousel').carousel({
        interval: 100000
    })

}



